//: generics/Mixins.java
package java_thinking.unit_15._15_15;
import java.util.*;

/**
 * 混型
 * 与接口混合
 */
interface TimeStamped {
    long getStamp();
}

class TimeStampedImp implements TimeStamped {
  private final long timeStamp;
  public TimeStampedImp() {
      timeStamp = new Date().getTime();
  }
  @Override
  public long getStamp() {
      return timeStamp;
  }
}

interface SerialNumbered {
    long getSerialNumber();
}

class SerialNumberedImp implements SerialNumbered {
  private static long counter = 1;
  private final long serialNumber = counter++;
  @Override
  public long getSerialNumber() {
      return serialNumber;
  }
}

interface Basic {
  public void set(String val);
  public String get();
}

class BasicImp implements Basic {
  private String value;
  @Override
  public void set(String val) {
      value = val;
  }
  @Override
  public String get() {
      return value;
  }
}

class Mixin extends BasicImp implements TimeStamped, SerialNumbered {
    private TimeStamped timeStamp = new TimeStampedImp();
    private SerialNumbered serialNumber =
        new SerialNumberedImp();
    @Override
    public long getStamp() {
        return timeStamp.getStamp();
    }
    @Override
    public long getSerialNumber() {
        return serialNumber.getSerialNumber();
    }
}

public class _15_1_Mixins {
  public static void main(String[] args) {
    Mixin mixin1 = new Mixin(), mixin2 = new Mixin();
    mixin1.set("test string 1");
    mixin2.set("test string 2");
    System.out.println(mixin1.get() + " " + mixin1.getStamp() +  " " + mixin1.getSerialNumber());
    System.out.println(mixin2.get() + " " + mixin2.getStamp() +  " " + mixin2.getSerialNumber());
  }
} /* Output: (Sample)
test string 1 1132437151359 1
test string 2 1132437151359 2
*///:~
